import React from 'react'
import styles from './Spider.css'
import Highcharts from 'highcharts-release/highcharts.js'
import Highchartsq from 'highcharts-release/highcharts-more.js'
Highchartsq(Highcharts)
type Props = {
  xData: Array,
  chartData: Array,
  title: String
}
class Spider extends React.Component {
  props: Props

  componentDidMount () {
    this.draw()
  }

  componentDidUpdate () {
    this.draw()
  }

  draw () {
    const container = this.refs.container
    let innerChart = Highcharts.chart(container, {
      colors: ['#00d2ff', '#00ffcc', '#00ff2a', '#30ff00', '#7798BF', '#aaeeee', '#ff0066', '#eeaaee',
        '#55BF3B', '#DF5353', '#7798BF', '#aaeeee'
      ],
      chart: {
        backgroundColor: 'transparent',
        polar: true,
        type: 'line',
        style: {
          fontFamily: '\'Unica One\', sans-serif'
        }
      },
      title: {
        text: this.props.title,
        x: -20,
        style: {
          color: '#E0E0E3',
          textTransform: 'uppercase',
          fontSize: '16px'
        }
      },
      credits:{
        enabled: false
      },
      tooltip: {
        shared: true,
        backgroundColor: 'rgba(0, 0, 0, 0.85)',
        style: {
          color: '#F0F0F0'
        }
      },
      pane: {
        size: '80%'
      },
      legend: {
        align: 'right',
        verticalAlign: 'top',
        y: 70,
        layout: 'vertical',
        itemStyle: {
          color: '#E0E0E3'
        },
        itemHoverStyle: {
          color: '#FFF'
        },
        itemHiddenStyle: {
          color: '#606063'
        }
      },
      xAxis: {
        gridLineColor: '#bebebe',
        labels: {
          style: {
            color: '#fff'
          }
        },
        categories: this.props.xData,
        tickmarkPlacement: 'on',
        lineWidth: 0
      },
      yAxis: {
        gridLineInterpolation: 'polygon',
        lineWidth: 0,
        min: 0,
        gridLineColor: '#bebebe',
        labels: {
          style: {
            color: '#808987'
          }
        }
      },
      plotOptions: {
        line: {
          lineWidth: 1,
          dataGrouping: {
            enabled: false
          }
        },
        series: {
          animation: true
        }
      },
      series: this.props.chartData
    })
    setTimeout(() => {
      if (innerChart) {
        innerChart.reflow()
      }
    }, 5)
  }

  render () {
    return (
      <div ref='container' className={styles['container']} />
    )
  }
}
export default Spider
